<?php

// taken from the php documentation http://php.net/manual/en/function.array-merge-recursive.php
// but I have modified it that it will only merge keys that exist in the first array, which means
// that the same key must exist in array2

function array_merge_recursive_distinct ( array &$array1, array &$array2 )
{
	$merged = $array1;

	foreach ( $array2 as $key => &$value )
	{
		if ( is_array ( $value ) && isset ( $merged [$key] ) && is_array ( $merged [$key] ) )
		{
			$merged [$key] = array_merge_recursive_distinct ( $merged [$key], $value );
		}
		else
		{
			if ( isset($merged[$key]) )
				$merged [$key] = $value;
		}
	}

	return $merged;
}	

function aasort (&$array, $key) 
{
	$sorter=array();
	$ret=array();
	reset($array);
	foreach ($array as $ii => $va) {
		$sorter[$ii]=$va[$key];
	}
	asort($sorter);
	foreach ($sorter as $ii => $va) {
		$ret[$ii]=$array[$ii];
	}
	$array=$ret;
}

?>